package awk.script.javassist.method04.proxy.bytebuddy;

import awk.script.javassist.method04.proxy.TargetMethod;

/**
 * @author yujianlong
 * @create 2021-03-29 17:16
 **/
public class ByteBuddyProxyTest {

	public static void main(String[] args) throws Exception {
		//通过代理类方式
//		Class<TargetMethod> proxyClass = ByteBuddyProxy.getProxy(TargetMethod.class);
//
//		Constructor<TargetMethod> constructor = proxyClass.getConstructor(new Class[]{});
//		TargetMethod targetMethod = constructor.newInstance(new Object[]{});
////		TargetMethod targetMethod = proxyClass.newInstance();
//
////		String invoke = (String) proxyClass.getMethod("testMethod", new Class[]{String.class, Integer.class}).invoke(targetMethod, "zhang", 17);
//		String invoke = (String) proxyClass.getMethod("testMethod2", new Class[]{String.class, Integer.class}).invoke(targetMethod, "zhang", 17);

		//通过代理对象方式

		TargetMethod proxyObject = ByteBuddyProxy.getProxyObject(TargetMethod.class, new Class[]{}, new Object[]{});

		proxyObject.testMethod2("zhang", 18);
	}

	public static void main4(String[] args) throws Exception {
		Class<TargetMethod> proxyClass = ByteBuddyProxy.getProxy(TargetMethod.class, "testMethod", new Class[]{String.class, Integer.class});

		TargetMethod targetMethod = proxyClass.newInstance();

//		String invoke = (String) proxyClass.getMethod("testMethod", new Class[]{String.class, Integer.class}).invoke(targetMethod, "zhang", 17);
		String invoke = (String) proxyClass.getMethod("testMethod", new Class[]{String.class, Integer.class}).invoke(targetMethod, "zhang", 17);
	}
}

